<?php
/**
 * Created by PhpStorm.
 * User: tangchao
 * Date: 19-3-12
 * Time: 下午4:38
 */

namespace App\HttpController\Api;

use EasySwoole\Core\Http\AbstractInterface\Controller;

class Base extends Controller
{
    public $params;
    public function index()
    {

    }

    public function onRequest($action):?bool
    {
        $params = $this->request()->getQueryParams();
        $params['page'] = !empty($params['page']) ? $params['page'] : 1;
        $this->params = $params;
        return true;
    }
//todo 上线时再开启
//    public function onException(\Throwable $throwable,$actionName):void
//    {
//        $this->writeJson(501,'服务端出了问题');
//    }

    /**
     * 返回错误
     * @param string $msg
     * @return bool
     */
    public function backError($msg = 'error')
    {
        return $this->writeJson(200,[],$msg);
    }

    /**
     * 返回成功
     * @param string $msg
     * @param array $data
     * @return bool
     */
    public function backSuccess($data = [],$msg = 'success')
    {
        return $this->writeJson(200,$data,$msg);
    }
}